import xml.dom.minidom
import xml.etree.ElementTree as ET

import requests


def pretty_print_xml(element):
    # 将 ElementTree 转换为字符串
    rough_string = ET.tostring(element, 'utf-8')
    # 使用 minidom 进行格式化
    reparsed = xml.dom.minidom.parseString(rough_string)
    return reparsed.toprettyxml(indent="  ")


def __new_alarm__():
    wsdl_url = "http://10.10.80.215:7501/services/InterSwitchAlarm?wsdl"
    headers = {'content-type': 'text/xml;charset=UTF-8',
               'User-Agent': 'Apache-HttpClient/4.5.5 (Java/16.0.1)',
               'SOAPAction': 'application/soap+xml;charset=utf-8'
               }
    # 当派单的 sheetNo 为空，则是新建
    with open('/Users/chipingyung/AquaProjects/python/xz/data/派单入参.xml', encoding='utf-8') as xml_file:
        body = xml_file.read()

    response = requests.post(wsdl_url, data=body, headers=headers, verify=False)
    root = ET.fromstring(response.text)

    # 格式化打印xml
    pretty_xml = pretty_print_xml(root)
    print(pretty_xml)

    # 原始响应结果
    # print(response.text)


# 	<!--集客故障流程工单接口，建立集客故障工单-->
def __new_async__():
    wsdl_url = "http://10.10.80.215:7501/services/InterSwitchAlarm?wsdl"
    # wsdl_url = "http://localhost:7501/services/CustomersAlarm?wsdl"
    headers = {'content-type': 'text/xml;charset=UTF-8',
               'User-Agent': 'Apache-HttpClient/4.5.5 (Java/16.0.1)',
               'SOAPAction': 'application/soap+xml;charset=utf-8'
               }

    with open('/Users/chipingyung/AquaProjects/python/xz/data/同步追单故障清除时间.xml', encoding='utf-8') as xml_file:
        body = xml_file.read()

    response = requests.post(wsdl_url, data=body, headers=headers, verify=False)
    root = ET.fromstring(response.text)

    # 格式化打印xml
    pretty_xml = pretty_print_xml(root)
    print(pretty_xml)

    # 原始响应结果
    # print(response.text)


if __name__ == '__main__':
    __new_alarm__()
    # __new_async__()
